package com.ruoyi.project.hissystem.controller;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.hissystem.domain.HisDepartment;
import com.ruoyi.project.hissystem.service.IHisDepartmentService;
import com.ruoyi.project.system.domain.SysPost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/*
* HIS系统管理/科室管理
* */
@RestController
@RequestMapping("/hissystem/department")
public class HisDepartmentController extends BaseController {
    @Autowired
    private IHisDepartmentService departmentService;

    //声明单元方法：查询科室信息
    @PreAuthorize("@ss.hasPermi('hissystem:department:list')")
    @GetMapping("/list")
    public TableDataInfo list(HisDepartment hisDepartment)
    {
        startPage();
        List<HisDepartment> list = departmentService.selDepartmentList(hisDepartment);
        return getDataTable(list);
    }
    //导出
    @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
    @PreAuthorize("@ss.hasPermi('hissystem:department:export')")
    @GetMapping("/export")
    public AjaxResult export(HisDepartment hisDepartment)
    {
        List<HisDepartment> list = departmentService.selDepartmentList(hisDepartment);
        ExcelUtil<HisDepartment> util = new ExcelUtil<HisDepartment>(HisDepartment.class);
        return util.exportExcel(list, "科室数据");
    }

    /**
     * 新增科室
     */
    @PreAuthorize("@ss.hasPermi('hissystem:department:add')")
    @Log(title = "科室管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HisDepartment hisDepartment)
    {
        hisDepartment.setCreateBy(SecurityUtils.getUsername());
        return toAjax(departmentService.insertDepartment(hisDepartment));
    }

    /**
     * 根据科室编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('hissystem:department:query')")
    @GetMapping(value = "/{departId}")
    public AjaxResult getInfo(@PathVariable Long departId)
    {
        return AjaxResult.success(departmentService.selectDeapartById(departId));
    }
    /**
     * 修改科室
     */
    @PreAuthorize("@ss.hasPermi('hissystem:department:edit')")
    @Log(title = "科室管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HisDepartment hisDepartment)
    {
        hisDepartment.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(departmentService.updateDepartment(hisDepartment));
    }

    /**
     * 删除科室
     */
    @PreAuthorize("@ss.hasPermi('hissystem:department:remove')")
    @Log(title = "科室管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{departIds}")
    public AjaxResult remove(@PathVariable Long[] departIds)
    {
        return toAjax(departmentService.deleteDepartmentByIds(departIds));
    }


}
